﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DataLayer;
using System.Xml.Serialization;
using System.IO;
using System.Xml;
using DataImporterConsole.Screens;

namespace DataImporterConsole {
    class Program {
        static void Main(string[] args) {
            int x;
            char ch = '0';
            ConsoleKeyInfo cki;

            Console.TreatControlCAsInput = true;

            ScreenLibrary sl = new ScreenLibrary();
            sl.Display();

            cki = Console.ReadKey();
            while (cki.Key != ConsoleKey.Escape) {
                ch = cki.KeyChar;
                Console.WriteLine();
                try {
                    int i;
                    if (Int32.TryParse(ch.ToString(), out i)) {
                        if( sl.isValidInput(ch)){
                            sl.Action(ch);
                        }
                        else{
                            Console.WriteLine(sl.InputError);
                        }
                    }
                    else {
                        Console.WriteLine(sl.InputError);
                    }
                }
                catch (OverflowException e) {
                    Console.WriteLine("You managed to fuck it up with {0}.", cki.Key);
                }
                cki = Console.ReadKey();
            }
        }

        public static void CreateBasicSpellFile() {
            DataSpell[] spellarray = new DataSpell[2];

            DataSpell spell = new DataSpell();
            spell.CastingTime = 2.0;
            spell.Coefficient = 0.7;
            spell.OTCoefficient = 0.3;
            spell.Cooldown = 0;
            spell.CostType = CostType.Fixed;
            spell.DirectMeanValue = 1892.5;
            spell.DirectMeanRange = 677.5;
            spell.Duration = 21.0;
            spell.ManaCost = 675;
            spell.Name = "Regrowth";
            spell.OvertimeValue = 182;
            spell.Rank = 10;
            spell.SchoolUsed = SpellSchool.Nature;
            spell.SpellType = SpellType.Heal;
            spell.TicksLength = 3.0;

            DataSpell otherspell = new DataSpell();
            otherspell.CastingTime = 3.5;
            otherspell.Coefficient = 1;
            otherspell.CostType = CostType.Fixed;
            otherspell.Cooldown = 0;
            otherspell.DirectMeanValue = 2952;
            otherspell.DirectMeanRange = 245;
            otherspell.Duration = 0;
            otherspell.ManaCost = 935;
            otherspell.Name = "Healing Touch";
            otherspell.OvertimeValue = 0;
            otherspell.Rank = 13;
            otherspell.SchoolUsed = SpellSchool.Nature;
            otherspell.SpellType = SpellType.Heal;
            otherspell.TicksLength = 0;

            spellarray[0] = spell;
            spellarray[1] = otherspell;



            XmlSerializer ser = new XmlSerializer(typeof(DataSpell[]));
            FileStream fs = new FileStream(@"C:\Private\Code\datafiles\onespell.xml", FileMode.Create);
            //XmlTextWriter textWriter = new XmlTextWriter(fs, Encoding.UTF8);

            //ser.Serialize(textWriter, spell);
            ser.Serialize(fs, spellarray);
            fs.Close();
        }
    }
}
